#include <stdio.h>  
#include <mysql/mysql.h>  
#include <string.h>  
void show_3(MYSQL *mysql){  
	printf("        根据学生 ID 列出该学生选择的所有课程和成绩信息        \n"); 
	MYSQL_RES  *res = NULL;  
	MYSQL_ROW   row;  
	char data[1024];  
	int  h, i, fields;  
	int   rows;  
	int id,id1;
	int f;
	printf("1.根据学生ID查询\t2.根据课程ID查询:\n");
	scanf("%d",&f);
	switch(f){
	case 1:
		printf("查询学生的信息:输入学生ID:");                             
		scanf("%d",&id);                                                         
		sprintf(data,"select student.id,subject.sub,stusub.source from student,subject,stusub where student.id=stusub.stid and subject.id=stusub.suid and student.id='%d'",id); 
		h = mysql_real_query(mysql, data, strlen(data));  
		if (0 != h) {  
		printf("mysql_real_query(): %s\n", mysql_error(mysql));  
		}  
	break;
	case 2:
		printf("查询学生信息:输入学生课程ID:");                             
		scanf("%d",&id1);                                                         
		sprintf(data,"select student.id,student.name,subject.sub from student,subject,stusub where student.id=stusub.stid and subject.id=stusub.suid and subject.id='%d'",id1); 
		h = mysql_real_query(mysql, data, strlen(data));  
		if (0 != h) {  
		printf("mysql_real_query(): %s\n", mysql_error(mysql));  
		}
	break;
	}
	res = mysql_store_result(mysql);  
	if (NULL == res) {  
		printf("mysql_restore_result(): %s\n", mysql_error(mysql));  
	}  
	rows = mysql_num_rows(res);  
	printf("信息表一共有%d列\n", rows);  
	fields = mysql_num_fields(res);  
	printf("信息表一共有%d行\n", fields); 
	while ((row = mysql_fetch_row(res))) {  
		for (i = 0; i < fields; i++) {  
			printf("%s\t", row[i]);  
		}  
		printf("\n");  
	}  
}  

